package com.example.crmdemo.Crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.crmdemo.Crm.entity.Area;
import com.example.crmdemo.Crm.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    // 添加区域
    @PostMapping("/add")
    public boolean addArea(@RequestBody Area area) {
        return areaService.save(area);
    }

    // 删除区域
    @DeleteMapping("/delete/{a_name}")
    public boolean deleteArea(@PathVariable String a_name) {
        return areaService.removeById(a_name);
    }

    // 修改区域信息
    @PutMapping("/update")
    public boolean updateArea(@RequestBody Area area) {
        return areaService.updateById(area);
    }

    // 按区域名查询区域
    @GetMapping("/get/{a_name}")
    public Area getAreaByName(@PathVariable String a_name) {
        return areaService.getById(a_name);
    }

    // 获取所有区域信息
    @GetMapping("/getall")
    public List<Area> getAllAreas() {
        return areaService.list();
    }
}
